/**
 * Created by zmh on 2017/2/25.
 */
$(function(){
    var page = 1, maxPage = 1;
    var prev = document.getElementsByClassName("prev_page")[0];
    var next = document.getElementsByClassName("next_page")[0];
    var select = document.getElementsByClassName("page_select")[0];
    updataPage(page);
    next.onclick = function(){
        if(page < maxPage){
            page++;
            updataPage(page);
        }
    };
    select.onchange = function(){
        page = this.value;
        updataPage(page);
    };
    prev.onclick = function(){
        if(page > 1){
            page--;
            updataPage(page);
        }
    };
    function updataPage(page){
        $.ajax({
            url:"http://192.168.23.25:3000/api/getmoneyctrl",
            dataType:"json",
            data:{
                pageid:page
            },
            success:function(data){
                maxPage = Math.ceil(data.totalCount / data.pagesize);
                var moneyctrlLis = template("moneyctrlLis",data);
                document.getElementById("moneyctrl_items").innerHTML = moneyctrlLis;
                var options = ""
                for(var i = 1 ; i <= maxPage ; i++){
                    if(page == i){
                        options += "<option selected value='" + i + "'> " + i + " / " + maxPage + "</option>";
                    } else {
                        options += "<option value='" + i + "'> " + i + " / " + maxPage + "</option>";
                    }
                }
                document.getElementsByClassName("page_select")[0].innerHTML = options;
            }
        })
    }
});
